package ml.tewas.gui;

import java.awt.Dimension;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class MenuPanel extends JPanel {


	private static final long serialVersionUID = 1L;
	private JLabel targetNumberLabel;
	private JTextField targetNumberField;
	private JButton generate;
	private JButton play;
	private JButton pause;
	private JLabel trainWALabel;
	private JTextField trainNumberField;
	private JLabel totalTrainCountLabel;
	private JLabel totalTrainCount;
	private JLabel agentsWonLabel;
	private JLabel agentsWon;
	private JLabel agentsLostLabel;
	private JLabel agentsLost;
	private JLabel speedLabel;
	private JTextField speed;
	private JButton train;
	private JLabel learningRateLabel;
	private JTextField learningRate;
	private JCheckBox coordination;

	
	public MenuPanel() {
		initialize();
		
	}

	private void initialize() {
		this.setPreferredSize(new Dimension(150, 760));
		this.setLayout(null);
		targetNumberLabel = new JLabel("Threat Count:");
		targetNumberLabel.setBounds(5, 5, 70, 25);
		targetNumberField = new JTextField();
		targetNumberField.setBounds(82, 5, 40, 25);
		targetNumberField.setText("12");
		generate = new JButton("GENERATE");
		generate.setBounds(5, 35, 100, 25); 
		play = new JButton("PLAY");
		play.setBounds(5, 65, 100, 25);
		pause = new JButton("PAUSE");
		pause.setBounds(5, 95, 100, 25);
		trainWALabel = new JLabel("Play Count:");
		trainWALabel.setBounds(5, 125, 70, 25);
		trainNumberField = new JTextField();
		trainNumberField.setBounds(82, 125, 40, 25);
		trainNumberField.setText("10");
		totalTrainCountLabel = new JLabel("Train Count:");
		totalTrainCountLabel.setBounds( 5, 155, 70, 25);
		totalTrainCount = new JLabel("0");
		totalTrainCount .setBounds( 72, 155, 70, 25);
		
		agentsWonLabel = new JLabel("Agents Won:");
		agentsWonLabel.setBounds( 5, 175, 70, 25);
		agentsWon = new JLabel("0");
		agentsWon .setBounds( 72, 175, 70, 25);
		
		agentsLostLabel = new JLabel("Agents Lost:");
		agentsLostLabel.setBounds( 5, 195, 70, 25);
		agentsLost = new JLabel("0");
		agentsLost .setBounds( 72, 195, 70, 25);
		
		speedLabel = new JLabel("Speed (ms):");
		speedLabel.setBounds( 5, 215, 70, 25);
		speed = new JTextField();
		speed.setBounds(82, 215, 40, 25); 
		speed.setText("1000");
		
		learningRateLabel = new JLabel("Learning Rate:");
		learningRateLabel.setBounds( 5, 245, 90, 25);
		learningRate = new JTextField();
		learningRate.setBounds(82, 245, 40, 25); 
		learningRate.setText("0.001f");
		
		coordination = new JCheckBox("Coordination");
		coordination.setBounds( 5, 270, 90, 25);
		coordination.setSelected(true);
		
		
		train = new JButton("TRAIN");
		train.setBounds(5, 295, 100, 25);
		
		
		this.add(targetNumberLabel);
		this.add(targetNumberField);
		this.add(generate);
		this.add(play);
		this.add(pause);
		this.add(trainWALabel);
		this.add(trainNumberField);
		this.add(totalTrainCountLabel);
		this.add(totalTrainCount);
		this.add(agentsWonLabel);
		this.add(agentsWon);
		this.add(agentsLostLabel);
		this.add(agentsLost);
		this.add(speedLabel);
		this.add(speed);
		this.add(train);
		this.add(learningRateLabel);
		this.add(learningRate);
		this.add(coordination);
		
	}
	
	public void setActionListener(ActionListener actionListener){
		
		generate.addActionListener(actionListener);
	}
	
	public void setPauseListener(ActionListener actionListener){
		
		pause.addActionListener(actionListener);
	}
	
	public void setPlayListener(ActionListener actionListener){
		
		play.addActionListener(actionListener);
	}
	
	public void setTrainListener(ActionListener actionListener){
		
		train.addActionListener(actionListener);
	}
	
	public int getThreatNumber(){
		
		return (new Integer(targetNumberField.getText())).intValue();
	}
	
	public int getSpeed(){
		return (new Integer(speed.getText())).intValue();
	}
	
	public int getTrainCount(){
		return (new Integer(trainNumberField.getText())).intValue();
	}
	
	public float getLearningRate(){
		
		return  (new Float(learningRate.getText())).floatValue();
	}
	
	public boolean getCoordination(){
		return coordination.isSelected();
	}
	
	public void setTrainResult(String total,String won, String lost){
		totalTrainCount.setText(total);
		agentsWon.setText(won);
		agentsLost.setText(lost);
	}
}
